<template>
    <div>
        <h1>商铺信息</h1>
        商铺名称:
        <input type="text" v-model="tiaoj.name">
        房屋状态:
        <select v-model="tiaoj.Tid" >
            <option value="0">//请选择//</option>
            <option v-for="d in xia" :value="d.Tid">{{ d.Ttype }}</option>
        </select>
        <input type="button" value="查询" @click="xians">
        <input type="button" value="重置" @click="choz">
        <br>
        <a href="https://localhost:7048/api/Base/daoc">导出数据</a>
        <table class="table">
            <thead>
                <tr>
                    <td>name</td>
                    <td>loceng</td>
                    <td>Phone</td>
                    <td>mianj</td>
                    <td>Tid</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{d.name}}</td>
                    <td>{{d.loceng}}</td>
                    <td>{{d.Phone}}****{{d.Phone}}</td>
                    <td>{{d.mianj}}</td>
                    <td :style="d.Ttype=='出租中'?'color: green;':'color: blue;'">{{d.Ttype}}</td>
                    <td>
                        <input type="button" value="删除" @click="shanchu(d.id)">
                        <input type="button" value="编辑" @click="bianj(d.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
const router =  useRouter();
const aa =ref([]);

onMounted(() => {
    xians();
    xiala();
});
const data = ref(
   [ {
    "name": "",
    "id": 0,
    "deltimes": "",
    "isdel": 0,
    "loceng": "",
    "mianj": "",
    "Phone": "",
    "Tid": 0,
    "Ttype": ""
  }]
)
const tiaoj = ref(
{
    
    name:"",
    Tid:0
}
)
const xians = ()=>{
    axios.get("https://localhost:7048/api/Base/Showone",{params:tiaoj.value}).then(res=>{
        data.value=res.data;
    })
}
//下拉
const xia=ref([
    {
    "Tid": 0,
    "Ttype": ""
  }
])
const xiala = ()=>{
    axios.get("https://localhost:7048/api/Base/ShowTwo").then(res=>{
        xia.value=res.data
    })
}

const choz = ()=>{
    tiaoj.value.name="",
    tiaoj.value.Tid=0
    xians()
}

//删除
const shanchu = (a:any)=>{
    if(!confirm("你确定删除吗?"))
    {
        return;
    }
    axios.get("https://localhost:7048/api/Base/Delone",{params:{id:a}}).then(res=>{
        if(res.data>0)
        {
            alert("删除成功");
            xians();
        }
        else
        {
            alert("删除失败");
        }
    })
}

//编辑
const bianj = (a:any)=>{
    router.push({path:'/Upt',query:{id:a}})
    
}
</script>

<style scoped>

</style>